package library.model;

import com.gooddies.reflection.fieldprocessing.fieldextractors.jdbcExctractor.JdbcField;

/**
 * @author Dmitry
 */
public class Author implements Comparable<Author> {

    @JdbcField(field = "id")
    private int id;
    @JdbcField(field = "first_name")
    private String firstName;
    @JdbcField(field = "last_name")
    private String secondName;
    @JdbcField(field = "middle_name")
    private String middleName;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getSecondName() {
        return secondName;
    }

    public void setSecondName(String secondName) {
        this.secondName = secondName;
    }

    public String getMiddleName() {
        return middleName;
    }

    public void setMiddleName(String middleName) {
        this.middleName = middleName;
    }

    public String getFullName() {
        String name = secondName;
        if (middleName != null && !middleName.isEmpty()) {
            name += " " + middleName;
        }

        if (firstName != null && !firstName.isEmpty()) {
            name += " " + firstName;
        }

        return name;

    }

    @Override
    public String toString() {
        return getFullName();
    }

    @Override
    public int compareTo(Author o) {
        return secondName.compareToIgnoreCase(o.getSecondName());
    }
}